package com.photography.controller;

import com.photography.entity.PageResult;
import com.photography.entity.Result;
import com.photography.entity.StatusCode;
import com.photography.pojo.Customer;
import com.photography.pojo.CustomerVo;
import com.photography.service.CustomerService;
import com.photography.service.impl.CustomerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author weic
 * 客户Customer
 */
@RestController
@RequestMapping("customer")
@CrossOrigin
public class CustomerController {

    @Resource
    private CustomerService customerService;
    @GetMapping
    public Result findAll(Customer customer,
                          @RequestParam(defaultValue = "1",required = true) Integer page,
                          @RequestParam(defaultValue = "50",required = true) Integer size){
        PageResult<Customer> pageResult = customerService.findAll(customer, page, size);
        //返回数据
        return new Result(true, StatusCode.OK, "查询成功", pageResult);
    }

    @GetMapping("/findone")
    public Result findOne(String phonenumber){

        Customer customer = customerService.findOne(phonenumber);
        //返回数据
        return new Result(true, StatusCode.OK, "查询成功", customer);
    }
    @PostMapping
    public Result addCustomer(@RequestBody CustomerVo customerVo){
        customerService.addCustomer(customerVo);
        return new Result(true, StatusCode.OK, "添加成功");
    }

    @PutMapping
    public Result updateCustomer(@RequestBody Customer customer){
        customerService.updateCustomer(customer);
        return new Result(true, StatusCode.OK, "修改成功");
    }
//
//    //updatecustomer
//    @PostMapping("update")
//    public Result updateCustomer(Customer customer){
//        customerService.update(customer);
//        return Result.ok();
//    }
//
    @PostMapping("delete")
    public Result deleteCustomer(@RequestBody Customer customer){
        customerService.deleteCustomer(customer);
        return new Result(true, StatusCode.OK, "删除成功");
    }
//
//    @DeleteMapping
//    public Result deleteCustomer(String id){
//        customerService.deleteCustomer(id);
//        return Result.ok();
//    }
}
